# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=m2r
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.2.1
pkgrel=2
pkgdesc='"Markdown to reStructuredText converter" (mingw-w64)'
arch=('any')
url="https://github.com/miyakogi/m2r"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-docutils" "${MINGW_PACKAGE_PREFIX}-python-mistune")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pygments" "${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
source=("https://github.com/miyakogi/m2r/archive/v$pkgver.tar.gz")
sha256sums=('9286c1a5d7548f34b0a12017444e4c441781bef4b71f321f723e314b76b6c498')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  local _PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/m2r-script.py"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
